package com.baibei.model;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * 交易参数
 * Created by ChenRui on 2017/8/8 0008 19:32.
 */
public class TradeParams implements Parcelable {
    /**
     * 交易类型
     */
    public TradeType type;

    /**
     * 购买数量
     */
    public int quantity;

    /**
     * 上升设置（百分比，比如：98%）
     */
    public int upPercent;

    /**
     * 下降设置（百分比，比如：98%）
     */
    public int downPercent;

    /**
     * 总金额
     */
    public double amount;

    /**
     * 订货服务费
     */
    public double fee;

    /**
     * 体验券
     */
    public CouponInfo couponInfo;

    /**
     * 实时价格
     */
    public double lastPrice;

    /**
     * 产品编号
     */
    public int productId;

    /**
     * 产品昨日关市价
     */
    public double close;

    public TradeParams() {
    }


    protected TradeParams(Parcel in) {
        quantity = in.readInt();
        upPercent = in.readInt();
        downPercent = in.readInt();
        amount = in.readDouble();
        fee = in.readDouble();
        couponInfo = in.readParcelable(CouponInfo.class.getClassLoader());
        lastPrice = in.readDouble();
        productId = in.readInt();
        close = in.readDouble();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(quantity);
        dest.writeInt(upPercent);
        dest.writeInt(downPercent);
        dest.writeDouble(amount);
        dest.writeDouble(fee);
        dest.writeParcelable(couponInfo, flags);
        dest.writeDouble(lastPrice);
        dest.writeInt(productId);
        dest.writeDouble(close);
    }

    public static final Creator<TradeParams> CREATOR = new Creator<TradeParams>() {
        @Override
        public TradeParams createFromParcel(Parcel in) {
            return new TradeParams(in);
        }

        @Override
        public TradeParams[] newArray(int size) {
            return new TradeParams[size];
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public String toString() {
        return "TradeParams{" +
                "type=" + type +
                ", quantity=" + quantity +
                ", upPercent=" + upPercent +
                ", downPercent=" + downPercent +
                ", amount=" + amount +
                ", fee=" + fee +
                ", couponInfo=" + couponInfo +
                ", lastPrice=" + lastPrice +
                ", productId=" + productId +
                ", close=" + close +
                '}';
    }

    //    @Override
//    public void writeToParcel(Parcel dest, int flags) {
//        dest.writeInt(this.type == null ? -1 : this.type.ordinal());
//        dest.writeInt(this.quantity);
//        dest.writeInt(this.upPercent);
//        dest.writeInt(this.downPercent);
//        dest.writeDouble(this.amount);
//        dest.writeDouble(this.fee);
//        dest.writeParcelable(this.couponInfo, flags);
//    }

//    protected TradeParams(Parcel in) {
//        int tmpType = in.readInt();
//        this.type = tmpType == -1 ? null : TradeType.values()[tmpType];
//        this.quantity = in.readInt();
//        this.upPercent = in.readInt();
//        this.downPercent = in.readInt();
//        this.amount = in.readDouble();
//        this.fee = in.readDouble();
//        this.couponInfo = in.readParcelable(CouponInfo.class.getClassLoader());
//    }

//    public static final Creator<TradeParams> CREATOR = new Creator<TradeParams>() {
//        @Override
//        public TradeParams createFromParcel(Parcel source) {
//            return new TradeParams(source);
//        }
//
//        @Override
//        public TradeParams[] newArray(int size) {
//            return new TradeParams[size];
//        }
//    };

//    @Override
//    public String toString() {
//        return "TradeParams{" +
//                "type=" + type +
//                ", quantity=" + quantity +
//                ", upPercent=" + upPercent +
//                ", downPercent=" + downPercent +
//                ", amount=" + amount +
//                ", fee=" + fee +
//                ", couponInfo=" + couponInfo +
//                '}';
//    }
}
